const { regPhone, regPassword, regName } = require('../config').reg
const { updnewPassword,
    updrnewPassword,
    updoldPassword } = require('../config').upd

// 注册参数验证
function checkParams(req, res, next) {
    //  const {}
    console.log(req.body)
    // 使用正则去验证格式正确不 
    const { rpassword, password, username, phone } = req.body

    if (!(rpassword == password) || !regName.test(username) || !regPassword.test(password) || !regPhone.test(phone)) {
        return res.send({ code: 5, message: '参数格式不正确' })
    }
    next()
}

//修改密码参数验证
function checkPassword(req, res, next) {
    console.log(req.body)
    const {
        id,
        newpassword,
        rnewpassword,
        oldpassword
    } = req.body
    // 判断参数是否传递 
    if (!(newpassword == rnewpassword) || !updnewPassword.test(newpassword) || !updrnewPassword.test(rnewpassword) || !updoldPassword.test(oldpassword)) {
        return res.send({ code: 5, message: '参数格式不正确' })
    }
    next()
}


module.exports = {
    checkParams,
    checkPassword
}